import Vue from 'vue'
import App from './App.vue'

import router from './router'
import store from './store'
import axios from 'axios'

import VueCookies from 'vue-cookies'

import ElementUI from 'element-ui';
import './assets/theme/index.css'
// import 'element-ui/lib/theme-chalk/index.css';
import echarts from 'echarts';
import CollapseTransition from 'element-ui/lib/transitions/collapse-transition';
import areaData from "./assets/js/data.js";

import VueAxios from 'vue-axios'

import util from './util.js'


Vue.config.productionTip = false

Vue.component(CollapseTransition.name, CollapseTransition)


Vue.use(VueAxios, axios)
Vue.use(ElementUI)
Vue.use(VueCookies)
// Vue.use(echarts)
Vue.prototype.$echarts = echarts;
Vue.prototype.$util = util

// window.addEventListener('beforeunload', e=>{
//   window.scroll(0,0)
// })

//跨域携带cookie
axios.defaults.withCredentials = true;

// 配置请求基础路径
// axios.defaults.baseURL = 'http://127.0.0.1:10001';
Vue.prototype.baseUrl = 'http://127.0.0.1:10001';
//axios拦截器，在发起请求之前执行
//nodejs跨域请求，post参数必须进行序列化，否则即使在后台允许跨域，后台无法接收请求
axios.interceptors.request.use(config => {

  //处理post请求参数, 进行参数序列化
  if (config.method == 'post') {

    //序列化post请求参数
    let paramsString = '';
    for (let key in config.data) {
      paramsString += `${key}=${config.data[key]}&`;
    }

    //重新赋值config.data
    config.data = paramsString.slice(0, -1);

  }

  //必须返回config
  return config;
})
// 
// router.afterEach((to, from, next) => {
//   // chrome
//   window.scrollTo(0, 0);
//   // chrome
//   document.getElementById('index').scrollTop = 0
//   // firefox
//   document.getElementById('index').scrollTop = 0
//   // safari
//   window.pageYOffset = 0;
// })



new Vue({
  router,
  store,
  data() {
    return {
      // isLogin: false,
      areaData: areaData,
    };
  },
  render: h => h(App)
}).$mount('#app')
